﻿using FluentNHibernate;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Conventions.Helpers;
using NHibernate;
using NUnit.Framework;
using Sinbiota.Model.Persistence.NHibernateMappings;

namespace SinBiota.UnitTests.NHibernate
{
    public class FixtureBase
    {

        protected SessionSource SessionSource { get; set; }
        protected ISession Session { get; private set; }
        [SetUp]
        public void SetupContext()
        {
            var cfg = Fluently.Configure()
                .Database(SQLiteConfiguration.Standard.ShowSql().InMemory);
            SessionSource = new SessionSource(cfg.BuildConfiguration()
                                                 .Properties, new TestModel());
            Session = SessionSource.CreateSession();
            SessionSource.BuildSchema(Session);
        }
        [TearDown]
        public void TearDownContext()
        {
            Session.Close();
            Session.Dispose();
        }
    }


    public class TestModel : PersistenceModel
    {
        public TestModel()
        {
            AddMappingsFromAssembly(typeof(UserMapping).Assembly);
            Conventions.Add(DefaultCascade.SaveUpdate());
        }
    }

}